The Concentration Game

Lab Objective: This is a continuation of the previous lab. Build simple user interfaces in Java and implement event handlers.

In this lab you will improve the concentration game you developed in the last lab.
  1. Add a second panel to the right of main panel that contains controls that can be used by the user to specify the number of cards desired in the game. For instance, you could use a JTextField to display the number of cards to be used, and two buttons,+ and -, that can be used to increment and decrement the card count, respectively.
  2. Add a menu bar to the game with the menu Game, that has menu items New and Exit. This code details the how-to of menus in Java. A menu item generates action events when selected. Your menu handler should respond to the menu item New by creating a new instance of the concentration game that has the number of cards specified by the user . Selecting Exit does the obvious. Note that setJMenuBar is a method defined in the JFrame class.
  3. Recall from our discussion in class that the method call gc.actionPerformed(new ActionEvent(c,1,"")) simulates a mouse click on card c. Use this to develop a systematic way of solving an instance of the concentration game.
  4. Test your game solver for deck sizes of 64, 128, and 256. What can you say about the relationship between the number of tries needed to solve the puzzle and the puzzle size? As in, when the puzzle size doubles, does the number of tries double too? Triple? Quadruple?
  5. How many tries do you think the systematic approach will require to solve a game with 512 cards? 1024 cards?